Skip to content

test-float-parse: Use an overrideable random seed#152598

Open
tgross35 wants to merge 3 commits intorust-lang:mainfrom
tgross35:test-float-parse-updates
Open

test-float-parse: Use an overrideable random seed#152598
tgross35 wants to merge 3 commits intorust-lang:mainfrom
tgross35:test-float-parse-updates

Conversation

@tgross35
Copy link
Copy Markdown
Contributor

Currently test-float-parse is mostly random tests which take a fixed
seed, meaning the same set of values get tested for each invocation.
This isn't ideal because we don't get the true benefit of randomness,
which is to have better coverage over time.

Improve this by using a randomly generated seed, which can also be set
via env. The seed is printed at the beginning of each run so it is easy
to reproduce failures using the same test set, if needed.

Typically it isn't great to have fuzzing randomness in tests that get
run in CI because it can lead to spurious failures. However, this is a
test for which failure should never happen becasue the algorithms are
reasonably well proven, so if one does occur it represents a very
unexpected bug that needs to be addressed. The error message is updated
to strongly recommend reporting before retrying and to include details
on how to reproduce.

Additionally there are two other commits with less notable changes,
details are in the messages there.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Feb 14, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Feb 14, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Mark-Simulacrum

@rust-log-analyzer

This comment has been minimized.

@tgross35 tgross35 force-pushed the test-float-parse-updates branch from e82bcb2 to 5939d5d Compare February 14, 2026 00:53
@rust-log-analyzer

This comment has been minimized.

@tgross35 tgross35 force-pushed the test-float-parse-updates branch from 5939d5d to b99607f Compare February 14, 2026 02:46
@tgross35
Copy link
Copy Markdown
Contributor Author

The new version of indicatif pulls in a new wasm dep tree, which we don't really need. Looks like they made these optional in 0.18.4 but it hasn't been released yet console-rs/indicatif#766, so can probably just wait for that.

@rust-log-analyzer

This comment has been minimized.

Copy link
Copy Markdown
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me either way, mostly just nits

View changes since this review

fn main() {
// Forward the opt level so we can warn if the tests are going to be slow.
let opt = env::var("OPT_LEVEL").expect("OPT_LEVEL unset");
let profile = env::var("PROFILE").expect("PROFILE unset");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to tell Cargo that we read these environment variables, or is that assumed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've always assumed that these trigger a rerun, but I actually have no idea. Asked about this at rust-lang/cargo#16800.

const SEED: [u8; 32] = *b"3.141592653589793238462643383279";
const SEED_ENV: &str = "TEST_FLOAT_PARSE_SEED";

/// Seed for tests that use a deterministic RNG, and its b64 representation for printing. Taken
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe save the dependency and just hex-dump? Should be fairly easy with something like {:#032x}{:032x} with u128...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, I did this.

@rust-bors

This comment has been minimized.

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 22, 2026
@tgross35 tgross35 force-pushed the test-float-parse-updates branch from b99607f to e7183bf Compare March 29, 2026 07:49
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 29, 2026

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 29, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Currently we warn if `debug_assertions` is set, but this isn't always
accurate because debug assertions can be on at higher optimization
levels. Forward some information from the build script and print it to
tell a better story, and update the warning to act on opt-level and
profile rather than `debug_assertions`.
Currently `test-float-parse` is mostly random tests which take a fixed
seed, meaning the same set of values get tested for each invocation.
This isn't ideal because we don't get the true benefit of randomness,
which is to have better coverage over time.

Improve this by using a randomly generated seed, which can also be set
via env. The seed is printed at the beginning of each run so it is easy
to reproduce failures using the same test set, if needed.

Typically it isn't great to have fuzzing randomness in tests that get
run in CI because it can lead to spurious failures. However, this is a
test for which failure should never happen becasue the algorithms are
reasonably well proven, so if one does occur it represents a very
unexpected bug that needs to be addressed. The error message is updated
to strongly recommend reporting before retrying and to include details
on how to reproduce.
@tgross35 tgross35 force-pushed the test-float-parse-updates branch from e7183bf to 32a2893 Compare March 29, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants